const BASEURL = getApp().globalData.BASEURL; //线上
const request = (config) => {
	console.log(config);
	let header = {
		"Content-Type": config.contentType || "application/json;charset=utf-8",
	}
	return new Promise((resove, reject) => {
		uni.request({
			url: BASEURL + config.url,
			data: config.data || '',
			header: {
				'Authorization': 'Bearer ' + uni.getStorageSync('token'),
				'token': uni.getStorageSync('token')
			},
			method: config.method,
			dataType: "json",
			success: (res) => {
				const {
					data
				} = res
				const {
					code,
					result
				} = data
				switch (code) {
					case 200:
						resove(res.data)
						break
					case 401:
						uni.reLaunch({
							url: '/pages/loging/loging'
						})
						break
					default:
						resove(res.data)
						uni.showToast({
							title: data.msg,
							duration: 2000,
							mask: false,
							icon: "none"
						})
				}
			},
			fail: (error) => {
				uni.showToast({
					title: "请求错误",
					duration: 1500,
					mask: false,
					icon: "none"
				});
				reject(error)
			},
			complete: () => {
				// setTimeout(() => {
				// 	uni.hideLoading()
				// }, 1500)
			}
		})
	})
}
export default request